package main

import (
	"fmt"
	"google.golang.org/protobuf/proto"
	"net"
	"network/SearchRequest"
)

func main() {
	server, err := net.Listen("tcp", ":8081")
	if err != nil {
		panic(err)
	}

	for {
		fmt.Println("server start")
		accept, err := server.Accept()
		if err != nil {
			panic(err)
		}
		go read(accept)
	}

}

func read(accept net.Conn) {
	buf := make([]byte, 22, 4096)
	for {
		n, err := accept.Read(buf)
		if n == 0 || err != nil {
			break
		}
		request := &SearchRequest.SearchRequest{}
		if err := proto.Unmarshal(buf, request); err != nil {
			panic(err)
		}
		fmt.Println(request)
	}
}
